package vivace.helper;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

import lib.Komponenter.ChampFrame;
import lib.Texter.Text;
import vivace.model.App;
import vivace.view.openDialogue.ImageFilter;

/**
 * Shared utility functions
 */
public class GUIHelper {
	
	/**
	 * The height of a track in the GUI. Applies to the rows in the Track List as
	 * well as the rows in the Track Content view.
	 */
	public final static int TRACK_HEIGHT = 25;
	
	/**
	 * The height of a note in the piano roll. Applies to the midi events in the Piano Roll as
	 * well as the bars in the Track Content view.
	 */
	public final static int NOTE_HEIGHT = 14;
	
	/**
	 * The height of a note in the piano roll. Applies to the midi events in the Piano Roll as
	 * well as the bars in the Track Content view.
	 */
	public final static int OCTA_HEIGHT = 112;
	
	/**
	 * The minimum width of a note in the piano roll. 
	 */
	public final static int MIN_NOTE_WIDTH = 6;
	
	
	/**
	 * The height of a track header in the GUI. Applies to the table header in the 
	 * Track List as well as the time line in the Overview.
	 */
	public final static int HEADER_HEIGHT = 39;
	
	/**
	 * The height of a track header in the GUI. Applies to the table header in the 
	 * Track List as well as the time line in the Overview.
	 */
	public final static int SCROLL_HEIGHT = 18;
	
	
	/**
	 * The height where the timelines top will begin.
	 */
	public final static int TIMELINE_TOP = 12;
	
	/**
	 * Spcifies the minimum rendering length of the timeline and gridhelper.
	 */
	public final static int MIN_TICKS = 16000;
	
	/**
	 * Minimum number of lines in vertical the overview/pianoroll should draw
	 */
	public static int OVERVIEW_HEIGHT;
	
	
	/**
	 * A reference to the ChampFrame  
	 */	
	public static ChampFrame appFrame;
	
	/**
	 * A reference to the image icon used in multiple 
	 * windows across the application
	 */
	public static Image icon = new ImageIcon("resources/vivace.png").getImage();
	
	/**
	 * Displays an error 
	 * @param component
	 */
	public static void displayError( Exception e ){
		displayError( e.getMessage() );
	}
	
	/**
	 * Displays an error 
	 * @param component
	 */
	public static void displayError( String key ){
		JOptionPane.showMessageDialog(null, Text.getText(key),Text.getText("ERROR_OCCURED"),JOptionPane.ERROR_MESSAGE);
	}
	
	/**
	 * Creates, formats and returns a JFileChooser 
	 */
	public static JFileChooser getJFileChooser(){
		
		JFileChooser fc = new JFileChooser();
	    fc.addChoosableFileFilter(new ImageFilter()); // Add a custom file filter
	    fc.setAcceptAllFileFilterUsed(false); // Disable the default (accept all) file filter
	    fc.setFileView(new vivace.view.openDialogue.ImageFileView()); // Add custom icons for file types.j
	    return fc;
		
	}
	
}